package org.example.com.pattern.create.prototype

abstract class Shape {
    var x: Int = 0
    var y: Int = 0
    var color: String = ""

    constructor()
    constructor(source: Shape) {
        this.x = source.x
        this.y = source.y
        this.color = source.color
    }

    abstract fun clone(): Shape
}

class Rectangle : Shape {
    var width: Int = 0
    var height: Int = 0

    constructor() : super()
    constructor(source: Rectangle) : super(source) {
        this.width = source.width
        this.height = source.height
    }

    override fun clone(): Shape {
        return Rectangle(this)
    }
}

class Circle : Shape {
    var radius: Int = 0

    constructor() : super()
    constructor(source: Circle) : super(source) {
        this.radius = source.radius
    }


    override fun clone(): Shape {
        return Circle(this)
    }
}

class Application {
    private val shapes = ArrayList<Shape>()

    init {
        val circle = Circle()
        circle.radius = 20
        circle.x = 10
        circle.y = 10
        shapes.add(circle)
        val anotherCircle = circle.clone()
        shapes.add(anotherCircle)

        val rectangle = Rectangle()
        rectangle.width = 10
        rectangle.height = 20
        shapes.add(rectangle)
    }

    fun businessLogic() {
        val arrayList = ArrayList(shapes)
        shapes.forEach {
            arrayList.add(it.clone())
        }
        println(arrayList.size)
    }
}

fun main() {
    val app = Application()
    app.businessLogic()
}